package cn.com.oceansoft.business.mobile.danger.util;

import cn.com.oceansoft.business.danger.entity.Wzzj;
import cn.com.oceansoft.nos.common.util.HttpClientUtil;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by OS on 2018/6/1.
 */
public class PicZzThread extends Thread{
//    final private static String pvUrl = "http://192.168.1.2:8089/fastdfs/api/fastdfs/upload";
    final private static String pvUrl = "http://172.16.3.6/jdcj_fastdfs_client/api/fastdfs/upload";
    Map<String, String> paraMap = new HashMap<String, String>();
    BASE64Encoder base64 = new BASE64Encoder();
    private Wzzj wzzj;
    private MultipartFile file;

    public PicZzThread() {
    }

    public PicZzThread(Wzzj wzzj, MultipartFile file) {
        this.wzzj = wzzj;
        this.file = file;
    }

    public void run() {
        System.out.println("PicThread.start()");
        try {
            String extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
            String base64str = base64.encode(file.getBytes());
            paraMap.put("orderdbid",wzzj.getId());
            paraMap.put("type","12");
            paraMap.put("base64",base64str);
            paraMap.put("extname",extName);
            HttpClientUtil.doPost(pvUrl,paraMap,"UTF-8");
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("PicZzThread.end()");
    }
}
